/* 我的流程 --- 复审 */
<template>
  <div>
    <Card :bordered="false">
      <p slot="title">复审</p>
      <div class="ivu-table-wrapper">
        <div class="ivu-table ivu-table-default ivu-table-border">
          <div class="ivu-table-header">
            <table cellspacing="0" cellpadding="0" border="1" width="100%">
              <thead>
                <th style="text-align:center">
                  <div class="ivu-table-cell">复审修改单</div>
                </th>
              </thead>
            </table>
          </div>
          <div class="ivu-table-body">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
              <tbody class="ivu-table-tbody">
                <tr class="ivu-table-row">
                  <td>
                    <div class="ivu-table-cell">复审人员</div>
                  </td>
                  <td>
                    <div class="ivu-table-cell">
                      {{info.faudit}}
                    </div>
                  </td>
                  <td>
                    <div class="ivu-table-cell">复审时间</div>
                  </td>
                  <td>
                    <div class="ivu-table-cell">
                      <p>第一次复审：2018-09-15 9:00</p>
                      <p>第二次复审：2018-09-15 16:00</p>
                    </div>
                  </td>
                </tr>
                <tr class="ivu-table-row">
                  <td>
                    <div class="ivu-table-cell">修改人员</div>
                  </td>
                  <td>
                    <div class="ivu-table-cell"><template>
                        <Select v-model="info.fModifier" @on-change="chengeXgry" :label-in-value="true">
                          <Option v-for="(item,index) in xzRy" :value="item.value" :label="item.label" :key="item.index">{{
                            item.label }}</Option>
                          <!-- <Option v-for="item in xzRy" :value="item.Staff_name" :key="item.staffs_name">{{ item.Staff_name }}</Option> -->
                        </Select>
                      </template></div>
                  </td>
                  <td>
                    <div class="ivu-table-cell">修改完成时间</div>
                  </td>
                  <td>
                    <div class="ivu-table-cell">
                      <p>第一次复审：2018-09-15 9:00</p>
                      <p>第二次复审：2018-09-15 16:00</p>
                    </div>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
      <template>
        <Table border highlight-row @on-row-click="getIndex" :columns="columns1" :data="info.Fushen" style="margin-top:10px;"></Table>
        <div style="border:1px solid #e8eaec;border-top:0;text-align:center;padding:10px 0;">
          <Button type="primary" :disabled="addBtton" style="margin-right:12px;width:80px;">添加</Button>
          <Button type="error" class="btnwidth">删除</Button>
        </div>
      </template>
      <div class="ivu-table-wrapper" style="margin-top:10px;">
        <div class="ivu-table ivu-table-default ivu-table-border">
          <div class="ivu-table-header">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
              <thead>
                <th style="text-align:center">
                  <div class="ivu-table-cell">报告（正文、附图附件附表）</div>
                </th>
              </thead>
            </table>
          </div>
          <div class="ivu-table-body">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
              <tbody class="ivu-table-tbody">
                <tr class="ivu-table-row">
                  <td>
                    <div class="ivu-table-cell">可上传多个文件
                      <template>
                        <Upload multiple action="//jsonplaceholder.typicode.com/posts/" style="display:inline-block;">
                          <Button icon="ios-cloud-upload-outline" style="color:#2996ff">上传</Button>
                        </Upload>
                      </template>
                    </div>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
      <div class="but">
        <Row>
          <Col span="12">
          <PrintButton v-if="flag" Url="print/printAuditForm" :Project_id="info.Id || $route.query.Project_id" Atype="复审"></PrintButton>
          </Col>
          <Col span="12" style="text-align:right;">
          <Button type="primary">保存</Button>
          <Button type="primary" style="margin:0 5px" @click="submit(3)">提交复审</Button>
          <Button type="primary" :disabled="stats" @click="submit(4)">提交终审</Button>
          </Col>
        </Row>
      </div>
      <StepBar :status="4" />
    </Card>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        allIndex: "",
        stats: true,
        addBtton: true,
        flag: false,
        xzRy: [],
        info: {},
        columns1: [{
          align: "center",
          title: "复审修改清单",
          children: [{
              type: "selection",
              width: 60,
              align: "center"
            },
            {
              type: "index",
              title: "序号",
              width: 80,
              align: "center",
              key: "num"
            },
            {
              title: "复审意见",
              key: "Audit_opinion",
              align: "center"
            },
            {
              title: "修改说明",
              key: "Revise_explain",
              align: "center",
              render: (h, {
                row,
                index
              }) => {
                return h('Input', {
                  props: {
                    type: 'text',
                    value: row.Revise_explain
                  },
                  on: {
                    'on-blur': (val) => {
                      this.info.Fushen[index].Revise_explain = val.target.value
                    }
                  }
                })
              }
            }
          ]
        }]
      };
    },
    mounted() {
      // 获取当前信息
      this.getProject(this.$route.query.Project_id, this.$route.query.Atype)
    },
    methods: {
      getIndex(data, index, event) {
        this.allIndex = index;
      },
      inputAdd(type) {
        this.info.Fushen.push({})
      },
      inputRemove(type) {
        this.info.Fushen.splice(this.allIndex, 1);
      },
      /* 获取当前创建项目 */
      getProject(Project_id, Atype) {
        axios.get('/audit/findByProject', {
          params: {
            Project_id,
            Atype
          }
        }).then(res => {
          console.log(res)
          this.info = res
          this.getDoaudit(this.info.level)
          this.flag = true
          if (this.info.Fushen.length != 0) {
            this.addBtton = !this.addBtton
          }
          this.getXgry()
          localStorage.projectType = 5
        })
      },
      getXgry() {
        axios.get('/audit/findStaff', {
          params: {
            Project_id: this.$route.query.Project_id
          }
        }).then(res => {
          this.xzRy = res.data
        })
      },
      chengeXgry(value) {
        console.log(value)
        axios.get('/assignjobs/setModifier', {
          params: {
            Project_id: this.$route.query.Project_id,
            Atype: "复审",
            Modifier: value.value
          }
        }).then(res => {
          console.log(res)
          let title = res._MESSAGE
          if (res._STATUS == 1) {
            this.$Modal.success({
              title
            })
          } else {
            this.$Modal.error({
              title
            })
          }
        })
      },
      // 保存 save / 提交 submit
      submit(type) {
        if (type == 4) {
          axios.get('/projectInformation/saveOrUpdateProject', {
            params: {
              btn_way: 2,
              Perject_type: 9,
              id: this.$route.query.Project_id
            }
          }).then(res => {
            let title = res.MESSAGE
            if (res._STATUS == 1) {
              this.$router.push({
                name: 'lastInstance',
                query: {
                  Project_id: this.$route.query.Project_id,
                  Atype: 4
                }
              })
            } else {
              this.$Modal.error({
                title
              })
            }
          })
        } else {
          let AuditReplyLists = this.info.Fushen
          if (AuditReplyLists.length == 0) {
            axios.get('/audit/isAudit', {
              params: {
                Project_id: this.$route.query.Project_id,
                Atype: type
              }
            }).then(res => {
              let title = res._MESSAGE
              if (res._STATUS == 1) {
                this.$Modal.success({
                  title: title + ':请进入我的审核流程'
                })
              } else {
                this.$Modal.error({
                  title
                })
              }
            }).catch(err => {
              this.$Modal.error({
                title: '请求失败'
              })
            })
          } else {
            axios.post('/auditreply/saveOrUpdateM', {
              AuditReplyLists
            }).then(res => {
              axios.get('/audit/isAudit', {
                params: {
                  Project_id: this.$route.query.Project_id,
                  Atype: this.$route.query.Atype
                }
              }).then(res => {
                let title = res._MESSAGE
                if (res._STATUS == 1) {
                  this.$Modal.success({
                    title: title + ':请进入我的审核流程'
                  })
                } else {
                  this.$Modal.error({
                    title
                  })
                }
              })
            }).catch(err => {
              alert('数据发送失败')
              return
            })
          }

        }

      },
      getDoaudit(type) {
        axios.get('/audit/doaudit', {
          params: {
            Project_level: type,
            Project_id: this.$route.query.Project_id
          }
        }).then(res => {
          this.stats = res.stats === '4' ? false : true
          console.log(res.stats)
        })
      },
    }
  };
</script>

<style lang="less">
  .but {
    margin-top: 10px;
  }
</style>